<?php
//including header.php 
include '../../include/header.php';
//including page.php (It is a class which contain functions)
include '../../libraries/page.php';
//created object for page.php
$page = new page();

session_start();

//if activation link request comes
if ($_GET['key']) {
    $code = $_GET['key'];
    $result = mysql_query("select * from users where randomcode = '$code'") or die(mysql_error());
    $user_data = mysql_fetch_array($result);
    $no_rows = mysql_num_rows($result) or die(mysql_error());
    if ($no_rows == 1) {
        if ($user_data['active'] === 'false') {
            //updating the database active field with 'true'.
            $result = mysql_query(
                    "UPDATE users SET active = 'true'
             WHERE randomcode = '$code'") or print 'There was an error: ' . mysql_error();
            //header("location:../../user/login");
        } else {
         $msg = $message[9];
        }
    } else {
       $msg = $message[10];
    }
}

//To get session
if ($page->get_session_admin()) {
    header("location:index.php");
}

//If data posted by the form
if ($_SERVER["REQUEST_METHOD"] == "POST") {

    $login = $page->admin_login($_POST['emailusername'], $_POST['password']);
    if ($login) {
// Login Success
        header("location:../admin/index");
    } else {
        //Login Failed
        $msg = $message[7];
    }
}
?>


<div class="navbar">
    <div class="navbar-inner">
        <ul class="nav">
            <li class="active"><a href="../groups/groups">Groups</a></li>
            <li><a href="../products/products">Products</a></li>
            <li><a href="../suppliers/suppliers">Suppliers</a></li>
        </ul>
        <a class="brand" href="../index.php"  id="right_title"><b style="color:#333;">Inventory</b></a>
        <i class="icon-home" id ="right"></i>
    </div>
</div>

<!----------------------------------Display the result message of Addition--------------------->
<div align="center"><? echo $msg; ?></div>

<!---------------------------------Login form----------------------------------------->
<form class="form-horizontal" method="POST" action="" >
    <h2 style="margin-left:22%;color:#777">Login</h2>
    <div class="control-group">
        <label class="control-label" for="inputEmail">Email</label>
        <div class="controls">
            <input type="email" id="inputEmail" placeholder="Email" name="emailusername">
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="inputPassword">Password</label>
        <div class="controls">
            <input type="password" id="inputPassword" placeholder="Password" name="password">
        </div>
    </div>
    <div class="control-group">
        <div class="controls">
           
            <a href="register">Sign up</a>
             <button type="submit" class="btn btn-inverse" style="margin-left: 95px">Sign in</button>
        </div>
    </div>
</form>
<?php
//including footer.php
include '../../include/footer.php';
?>